<template>
  <ul class="tabs" :class="{ [classPrefix + '-tabs']: classPrefix }">
    <li
      v-for="item in dataSource"
      :class="liClass(item)"
      :key="item.value"
      @click="select(item)"
      class="tabs-item"
      :style="{ height: height }"
    >
      {{ item.text }}
    </li>
  </ul>
</template>

<script lang="ts">
import Vue from "vue";
import { Component, Prop } from "vue-property-decorator";
type DataSourceItem = { text: String; value: String };
@Component({})
export default class Tabs extends Vue {
  @Prop(String) readonly value!: string;
  @Prop(String) classPrefix?: string;
  @Prop({ type: String, default: "48px" }) height!: string;
  @Prop({ required: true, type: Array })
  dataSource!: DataSourceItem[];
  liClass(item: DataSourceItem) {
    return {
      [this.classPrefix + "-tabs-item"]: this.classPrefix,
      selected: item.value === this.value,
    };
  }
  select(item: DataSourceItem) {
    this.$emit("update:value", item.value);
  }
}
</script>

<style lang="scss" scoped>
.tabs {
  background: #c0dcc3;
  display: flex;
  text-align: center;
  font-size: 18px;

  &-item {
    width: 50%;
    line-height: 48px;
    //height: 50px;
    display: flex;
    justify-content: center;
    align-content: center;
    position: relative;
    &.selected::after {
      content: "";
      position: absolute;
      bottom: 0;
      left: 0;
      width: 100%;
      height: 4px;
      background: #a2cca7;
    }
  }
}
</style>